package ui.model;
/*
 * The model for the the opened files of textbook
 */
import static constants.GTextbookConstants.language;

import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import org.w3c.dom.Element;


import ui.view.IndexTreeNode;
import ui.view.LangWarningPane;


public class GTModel extends Observable{

	// open a textbook and add it to the list
	
	
	
	/** the type of the model could be 
	 * a Document object -- for importing an xml file, 
	 * an IndexTreeNode -- for opening a category from the database,
	 * null 
	 */
	public void addModel(Document doc){
		if(doc != null){			
			modelList.add(doc.getDocumentElement());
			currentModelIndex = modelList.size()-1;
			setChanged();
			notifyObservers(modelList.get(currentModelIndex));
		}
	}
	
	public void addModel(String objectID){
		if(objectID != null){			
			modelList.add(objectID);
			currentModelIndex = modelList.size()-1;
			setChanged();
			notifyObservers(modelList.get(currentModelIndex));
		}
	}
	// construct a new file 
	public void newModel(String objectID){
		modelList.add(objectID);
		currentModelIndex = modelList.size()-1;
		setChanged();
	}
	
	// select a file
	public void selectModel(int i){
		if(i >= 0){
			currentModelIndex = i;
			setChanged();
			notifyObservers(new Integer(currentModelIndex));
		}else
			System.out.println("There is no selected book");
	}
	
	//remove a file
	public void removeModel(int i){
		modelList.remove(i);
		System.out.println("model" + i);
		if(modelList.size()==0){
			currentModelIndex = -1;
		}
		setChanged();
		notifyObservers(new Integer(i));
	}
	

	public Vector<Object> getModelList() {
		return modelList;
	}

	public void setModelList(Vector<Object> modelList) {
		this.modelList = modelList;
	}

	public int getCurrentModelIndex() {
		return currentModelIndex;
	}

	public void setCurrentModelIndex(int currentModelIndex) {
		this.currentModelIndex = currentModelIndex;
	}

	
	private Vector<Object> modelList = new Vector<Object>(1,1);  // the list of the opened files
	private int currentModelIndex = -1;           // when there is no file open, the index is set -1
}
